package com.it135.citytraffic.mapper;

import com.it135.citytraffic.pojo.entity.Crossing;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 动态检测的路口 Mapper 接口
 * </p>
 *
 * @author lh
 * @since 2024-05-21
 */
@Mapper
public interface CrossingMapper extends BaseMapper<Crossing> {

    void update(Crossing crossing);

    @Select("select count(*) from traffic_info ti,crossing c where c.name = ti.name and c.id = #{id}")
    Integer predictCount(Long id);

    @Select("select ti.blocked from traffic_info ti,crossing c where c.name = ti.name and c.id = #{id}")
    String[] predictBlock(Long id);

    @Select("select name from crossing where id = #{id}")
    String predictName(Long id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into crossing (name, level, position, create_time, forbidden, region, city_code) " +
            "VALUES (#{name}, #{level}, #{position}, #{createTime}, #{forbidden}, #{region}, #{cityCode})")
    void save(Crossing crossing);
}
